   package com.javalong.affairs.module.notifything.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.javalong.affairs.R;
import com.javalong.affairs.base.activity.UIHandlerActivity;
import com.javalong.affairs.module.notifything.adapter.ReceiverAdapter;
import com.javalong.affairs.module.notifything.adapter.ReceiverAdapter.Type;
import com.javalong.affairs.base.constant.BundleKey;
import com.javalong.affairs.base.constant.DataType;
import com.javalong.affairs.base.constant.MapKey;
import com.javalong.affairs.base.data.AllData;
import com.javalong.affairs.base.model.User;
import com.javalong.affairs.base.ui.SimplePullRefreshList;
import com.javalong.affairs.base.ui.TopTitle;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_delegator)
public class DelegatorActivity extends UIHandlerActivity implements
		OnItemClickListener {
	@ViewInject(R.id.ui_toptitle)
	private TopTitle topTitle;
	@ViewInject(R.id.lv_delegator)
	private SimplePullRefreshList lv_delegator;

	private ReceiverAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		topTitle.setOnLeftDrawableClick(this);
		List<User> userList = AllData.GetInstance().appendListData(
				R.string.data_delegate_users, new ArrayList<User>());
		adapter = new ReceiverAdapter(this, userList, Type.DELEGATE);
		lv_delegator.setAdapter(adapter);
		lv_delegator.initData(getMapData());
		lv_delegator.refresh();
		lv_delegator.setOnItemClickListener(this);
	}

	private Map<String, Object> getMapData() {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put(MapKey.ACTION_NAME, "User");
		param.put(MapKey.METHOD_NAME, "outList_entrust");
		param.put(MapKey.DATA_RESID, R.string.data_delegate_users);
		param.put(MapKey.DATA_TYPE, DataType.LIST_USER);
		return param;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// 返回user
		List<User> userList = (List<User>) AllData.GetInstance().get(
				R.string.data_delegate_users);
		Intent intent = new Intent();
		intent.putExtra(BundleKey.USER, userList.get(position - 1));
		setResult(RESULT_OK, intent);
		finish();
	}

}
